package analysen;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import datensaetze.Datensatz;
import de.dnb.music.title.FormalTitle;
import de.dnb.music.title.MusicTitle;
import de.dnb.music.title.ParseMusicTitle;
import de.dnb.music.version.Version;
import exceptions.NoPreferredNameException;
import exceptions.NoSuchItemException;
import utils.DownloadBearbeiter;

public class FassungB1 extends DownloadBearbeiter {

	int count = 0;

	@Override
	public void bearbeiteDS(Datensatz ds) {
		String s = "130 (.+)\\$v";
		Pattern pattern = Pattern.compile(s);
		String raw = ds.getRohdaten();
		Matcher matcher = pattern.matcher(raw);
		if (matcher.find()) {
			String titleS = matcher.group(1);
			MusicTitle title = ParseMusicTitle.parse(null, titleS);

			if (title.containsVersion() && !title.containsParts()) {
				Version f = title.getVersion();
				char fallgruppe = f.getFallgruppeParagraphM511();
				int untergruppe = f.getUntergruppe();
				if (fallgruppe == 'b' && untergruppe == 1) {
					System.out.println(raw);
					count++;
				}
			}
		}

	}

	/**
	 * @param args
	 * @throws NoSuchItemException 
	 * @throws NoPreferredNameException 
	 * @throws IOException 
	 */
	public static void main(String[] args)
		throws IOException,
		NoPreferredNameException,
		NoSuchItemException {
		FassungB1 fassungB1 = new FassungB1();
		fassungB1.bearbeiteFile("d:/normdaten/dma_V1.dwl");

		System.err.println(fassungB1.count);

	}

}
